package com.hgw.Demo02CommandPattern.Exercises17_10_4;

import java.util.ArrayList;

/**
 * Data time:2021/12/16 22:10
 * StudentID:2019112118
 * Author:hgw
 * Description:
 */
public class CommandQueue {
    private ArrayList<AbstractCommand> commands = new ArrayList<AbstractCommand>();

    public void addCommand(AbstractCommand command) {
        commands.add(command);
    }

    public void removeCommand(AbstractCommand command) {
        commands.remove(command);
    }

    // 循环调用每一个命令对象的 execute() 方法
    public void execute(int value) {
        for (AbstractCommand command : commands) {
            System.out.println(command.execute(value));
            System.out.println(command.undo());
        }
    }
}
